# -*- coding: utf-8 -*-

import time
from report import report_sxw
import pooler
from osv import osv
from tools.translate import _
import random
from datetime import datetime
import logging
        
class Parser(report_sxw.rml_parse):
    logging.getLoggerClass()
        
    def __init__(self, cr, uid, name, context):
        
        super(Parser, self).__init__(cr, uid, name, context=context)
        pool = pooler.get_pool(cr.dbname)
        self.pt_detail_obj = pool.get('ctsv.pt.detail')
        self.drl_result_obj = pool.get('ctsv.drl.result')
        self.sv_pt_obj = pool.get('ctsv.sinhvien.phongtrao')
        
        self.localcontext.update({
            'init': self._init,
            'lines': self.get_lines,
            'semester': self.get_semester,
            'name': self.get_name,
            'code': self.get_code,
            'drl': self.get_drl,
            'get_logo': self.get_logo,
        })
    
    def _init(self, drl_result):
        logging.info('----drl result ID : %s', drl_result.id)
        self.lines = self.drl_result_obj.get_all_lines(self.cr, self.uid, drl_result.id)
        logging.info('----LINE SIZE: %s', len(self.lines))
        drl_rs = self.drl_result_obj.browse(self.cr, self.uid, drl_result.id, context=False)
        self.semester = str(drl_rs.semester.name) + " (" + str(drl_rs.semester.academic_year.name) + ")"
        self.name = drl_rs.student_id.name
        self.code = drl_rs.student_id.code
        self.drl = self.sv_pt_obj.get_drl_result(self.cr, self.uid, drl_rs.student_id.id, drl_rs.semester.id, context=False)
        logging.info('----REPORT SEMESTER: %s', self.semester)
        return True

    def get_lines(self):
        return self.lines
    
    def get_semester(self):
        return self.semester
    
    def get_name(self):
        return self.name
    
    def get_code(self):
        return self.code
    
    def get_drl(self):
        return self.drl
    
    def get_logo(self):
        user = self.pool.get('res.users').browse(self.cr, self.uid, self.uid)
        logo = False
        if user.company_id:
            company = self.pool.get('res.company').browse(self.cr, self.uid, user.company_id.id)
            logo = company.logo
        return logo
    
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
